/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package liftsimulator;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Michael Peever & Alex Pool
 */
public class FloorUI extends JFrame {

    ImageIcon upImage = new ImageIcon("C:\\Users\\Peev\\Documents\\engineering\\third year\\Sem 2\\CP2013\\Elevator_SIM_2\\LiftSimulator151011\\src\\images\\UP.jpg");
    ImageIcon downImage = new ImageIcon("C:\\Users\\Peev\\Documents\\engineering\\third year\\Sem 2\\CP2013\\Elevator_SIM_2\\LiftSimulator151011\\src\\images\\DOWN.jpg");
    //Create Panels
    JPanel masterFloorPanel = new JPanel();
    JPanel floorPanel;
    JPanel fuiDirectionPanel = new JPanel();
    JPanel directionPanel = new JPanel();
    JLabel directionLbl = new JLabel();
    //create buttons
    JButton upBttn;
    JButton downBttn;
    //variables
    final int FLOOR_HEIGHT = 50;
    int noFloors;
    Lift l;
    int floorID;
    Building b;
    //Pictures

    public FloorUI(int noFloors, Lift l, Building b) {
        this.setLocation(1060, 320);
        this.setTitle("Floor Interface");
        //this.setLayout(new GridBagLayout());   
        this.setSize(new Dimension(300, (noFloors * FLOOR_HEIGHT + 50)));
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        this.b = b;


        masterFloorPanel.setSize(new Dimension(225, noFloors * FLOOR_HEIGHT));
        this.add(masterFloorPanel);
        this.noFloors = noFloors;
        this.l = l;
        createFloorsPanel();
    }

//    public void createDirectionPanel(String direction) {
//        for (int i = 0; i < 3; i++) {
//            if (direction.equals("UP")) {
//                directionLbl.setText("U");
//                fuiDirectionPanel.add(directionLbl);
//            } else {
//                directionLbl.setText("D");
//                fuiDirectionPanel.add(directionLbl);
//            }
//            masterFloorPanel.add(fuiDirectionPanel);
//        }
//
//
//    }

    public void createFloorsPanel() {

        if (b.region == "AUS/UK") {
            for (int i = noFloors - 1; i >= 0; i--) {
                setFloorID(i);
                floorPanel = new JPanel();//create floor panel
                floorPanel.setLayout(new GridLayout(1, noFloors));
                JLabel floorNumLabel = new JLabel();
                if (i == 0) {
                    floorNumLabel.setText("Floor: G");
                } else {
                    floorNumLabel.setText("Floor: " + Integer.toString(i));
                }
                final int k = i + 1;
                floorPanel.add(floorNumLabel);


                if (i != noFloors - 1) {
                    upBttn = new JButton();
                    upBttn.setText("UP");
                    floorPanel.add(upBttn);

                    upBttn.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            b.manualCallLift(k);
                        }
                    });
                } else {
                    JLabel blank1 = new JLabel();
                    floorPanel.add(blank1);

                }
                if (i != 0) {
                    downBttn = new JButton();
                    downBttn.setText("Down");
                    floorPanel.add(downBttn);
                    downBttn.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            b.manualCallLift(k);
                        }
                    });
                } else {
                    JLabel blank1 = new JLabel();
                    floorPanel.add(blank1);
                }



                masterFloorPanel.add(floorPanel);
            }
        } else {
            for (int i = noFloors; i >= 1; i--) {
                setFloorID(i);
                floorPanel = new JPanel();//create floor panel
                floorPanel.setLayout(new GridLayout(1, noFloors));
                JLabel floorNumLabel = new JLabel();
                floorNumLabel.setText("Floor: " + Integer.toString(i));
                final int k = i;
                floorPanel.add(floorNumLabel);

                if (i != noFloors) {
                    upBttn = new JButton();
                    upBttn.setText("UP");
                    floorPanel.add(upBttn);

                    upBttn.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            b.manualCallLift(k);
                        }
                    });
                } else {
                    JLabel blank1 = new JLabel();
                    floorPanel.add(blank1);

                }
                if (i != 1) {
                    downBttn = new JButton();
                    downBttn.setText("Down");
                    floorPanel.add(downBttn);
                    downBttn.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            b.manualCallLift(k);
                        }
                    });
                } else {
                    JLabel blank1 = new JLabel();
                    floorPanel.add(blank1);
                }



                masterFloorPanel.add(floorPanel);
            }
        }
    }

    
    

    public int getFloorID() {
        return this.floorID;
    }

    public void setFloorID(int idNum) {
        this.floorID = idNum;
    }
}